home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / client / messageBox.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  3.4 KB  |  109 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. function MessageCallback(%dlg,%callback)
  7. {
  8.    Canvas.popDialog(%dlg);
  9.    eval(%callback);
  10. }
  11.  
  12. // MBSetText resizes the message window, based on the change in size of the text
  13. // area.
  14.  
  15. function MBSetText(%text, %frame, %msg)
  16. {
  17.    %ext = %text.getExtent();
  18.  
  19.    %text.setText("<just:center>" @ %msg);
  20.    %text.forceReflow();
  21.  
  22.    %newExtent = %text.getExtent();
  23.  
  24.    %deltaY = getWord(%newExtent, 1) - getWord(%ext, 1);
  25.    %windowPos = %frame.getPosition();
  26.    %windowExt = %frame.getExtent();
  27.  
  28.    %frame.resize(getWord(%windowPos, 0), getWord(%windowPos, 1) - (%deltaY / 2), getWord(%windowExt, 0), getWord(%windowExt, 1) + %deltaY);
  29. }
  30.  
  31. //-----------------------------------------------------------------------------
  32. // MessageBox OK
  33. //-----------------------------------------------------------------------------
  34.  
  35. function MessageBoxOK( %title, %message, %callback )
  36. {
  37.     MBOKFrame.setText( %title );
  38.    Canvas.pushDialog( MessageBoxOKDlg );
  39.    MBSetText(MBOKText, MBOKFrame, %message);
  40.    MessageBoxOKDlg.callback = %callback;
  41. }
  42.  
  43. //------------------------------------------------------------------------------
  44. function MessageBoxOKDlg::onSleep( %this )
  45. {
  46.    %this.callback = "";
  47. }
  48.  
  49. //------------------------------------------------------------------------------
  50. // MessageBox OK/Cancel dialog:
  51. //------------------------------------------------------------------------------
  52.  
  53. function MessageBoxOKCancel( %title, %message, %callback, %cancelCallback )
  54. {
  55.     MBOKCancelFrame.setText( %title );
  56.    Canvas.pushDialog( MessageBoxOKCancelDlg );
  57.    MBSetText(MBOKCancelText, MBOKCancelFrame, %message);
  58.     MessageBoxOKCancelDlg.callback = %callback;
  59.     MessageBoxOKCancelDlg.cancelCallback = %cancelCallback;
  60. }
  61.  
  62. //------------------------------------------------------------------------------
  63. function MessageBoxOKCancelDlg::onSleep( %this )
  64. {
  65.    %this.callback = "";
  66. }
  67.  
  68. //------------------------------------------------------------------------------
  69. // MessageBox Yes/No dialog:
  70. //------------------------------------------------------------------------------
  71.  
  72. function MessageBoxYesNo( %title, %message, %yesCallback, %noCallback )
  73. {
  74.     MBYesNoFrame.setText( %title );
  75.    Canvas.pushDialog( MessageBoxYesNoDlg );
  76.    MBSetText(MBYesNoText, MBYesNoFrame, %message);
  77.     MessageBoxYesNoDlg.yesCallBack = %yesCallback;
  78.     MessageBoxYesNoDlg.noCallback = %noCallBack;
  79. }
  80.  
  81. //------------------------------------------------------------------------------
  82. function MessageBoxYesNoDlg::onSleep( %this )
  83. {
  84.    %this.yesCallback = "";
  85.    %this.noCallback = "";
  86. }
  87.  
  88. //------------------------------------------------------------------------------
  89. // Message popup dialog:
  90. //------------------------------------------------------------------------------
  91.  
  92. function MessagePopup( %title, %message, %delay )
  93. {
  94.    // Currently two lines max.
  95.    MessagePopFrame.setText( %title );
  96.    Canvas.pushDialog( MessagePopupDlg );
  97.    MBSetText(MessagePopText, MessagePopFrame, %message);
  98.    if ( %delay !$= "" )
  99.       schedule( %delay, 0, CloseMessagePopup );
  100. }
  101.  
  102. //------------------------------------------------------------------------------
  103.  
  104. function CloseMessagePopup()
  105. {
  106.    Canvas.popDialog( MessagePopupDlg );
  107. }
  108.  
  109.